\documentclass[UTF8,a4paper,fontset=fandol]{ctexart}
\usepackage{mathptmx}
\usepackage{amsmath,amsthm,amsfonts,amssymb,amscd}
\usepackage{multirow}
\usepackage{algorithm}
\usepackage{cases}
\usepackage{gbt7714}
\usepackage{subfigure}
\usepackage{enumerate}
\usepackage{setspace}
\usepackage{algorithmic}
\usepackage{extarrows}
\usepackage{latexsym}
\usepackage{longtable}
\usepackage{color}
\usepackage{etoolbox}
\usepackage{caption}     %修改图片表格名称字体字号的宏包
\DeclareCaptionLabelSeparator{twospace}{\ ~}
\captionsetup{labelsep=twospace}
\usepackage{float}        %自己设置图片插入位置
\usepackage{fancyhdr}     %设置页眉页脚的宏包
\setlength{\headheight}{43pt}
\usepackage{graphicx}     %插入图片
\usepackage{lastpage}     %引用最后一页
\usepackage{xcolor} 
\usepackage{makecell}
\usepackage[colorlinks,linkcolor=black, citecolor=black, unicode={true}]{hyperref}
\graphicspath{{figures/}} %%图片路径
\usepackage[a4paper,top=4cm,bottom=3cm,left=3.3cm,right=1.8cm]{geometry}  %设置页边距

\usepackage{fancybox}                      %画边界线
\usepackage{booktabs}
\usepackage{amsmath}
\usepackage{setspace}
\usepackage{array,caption}
\usepackage{listings}
\lstset{
 columns=fixed,       
 numbers=left,                                        % 在左侧显示行号
 numberstyle=\tiny\color{gray},                       % 设定行号格式
 frame=none,                                          % 不显示背景边框
 backgroundcolor=\color[RGB]{245,245,244},            % 设定背景颜色
 keywordstyle=\color[RGB]{40,40,255},                 % 设定关键字颜色
 numberstyle=\footnotesize\color{darkgray},           
 commentstyle=\it\color[RGB]{0,96,96},                % 设置代码注释的格式
 stringstyle=\rmfamily\slshape\color[RGB]{128,0,0},   % 设置字符串格式
 showstringspaces=false,                              % 不显示字符串中的空格
 language=python,                                        % 设置语言
 breaklines,%自动换行
 columns=flexible,%不随便添加空格,只在已经有空格的地方添加空格
}
\usepackage{multirow}
\usepackage[labelfont=bf]{caption}
\fancyput*(-0.8cm,-4.3cm){$|$}%
\fancyput*(-0.8cm,-4.9cm){$|$}%
\fancyput*(-0.8cm,-5.5cm){$|$}%
\fancyput*(-0.8cm,-6.1cm){$|$}%
\fancyput*(-0.8cm,-6.7cm){$|$}%
\fancyput*(-0.8cm,-7.3cm){$|$}%
\fancyput*(-0.8cm,-7.9cm){$|$}%
\fancyput*(-0.8cm,-8.5cm){$|$}%
\fancyput*(-0.8cm,-9.1cm){$|$}%
\fancyput*(-0.8cm,-9.7cm){$|$}%
\fancyput*(-1.0cm,-10.3cm){装}%
\fancyput*(-0.8cm,-10.9cm){$|$}%
\fancyput*(-0.8cm,-11.5cm){$|$}%
\fancyput*(-0.8cm,-12.1cm){$|$}%
\fancyput*(-0.8cm,-12.7cm){$|$}%
\fancyput*(-0.8cm,-13.3cm){$|$}%
\fancyput*(-1.0cm,-13.9cm){订}%
\fancyput*(-0.8cm,-14.5cm){$|$}%
\fancyput*(-0.8cm,-15.1cm){$|$}%
\fancyput*(-0.8cm,-15.7cm){$|$}%
\fancyput*(-0.8cm,-16.3cm){$|$}%
\fancyput*(-0.8cm,-16.9cm){$|$}%
\fancyput*(-1.0cm,-17.5cm){线}%
\fancyput*(-0.8cm,-18.1cm){$|$}%
\fancyput*(-0.8cm,-18.7cm){$|$}%
\fancyput*(-0.8cm,-19.3cm){$|$}%
\fancyput*(-0.8cm,-19.9cm){$|$}%
\fancyput*(-0.8cm,-20.5cm){$|$}%
\fancyput*(-0.8cm,-21.1cm){$|$}%
\fancyput*(-0.8cm,-21.7cm){$|$}%
\fancyput*(-0.8cm,-22.3cm){$|$}%
\fancyput*(-0.8cm,-22.9cm){$|$}%
\fancyput*(-0.8cm,-23.5cm){$|$}%

\floatstyle{plaintop}
\restylefloat{table}

\usepackage{listing}
\floatstyle{plain}
\restylefloat{listing}

\usepackage{enumitem}
\setlist[itemize]{labelindent=2em,leftmargin=*,itemsep=0pt,parsep=0pt}
\setlist[enumerate]{labelindent=2em,leftmargin=*,itemsep=0pt,parsep=0pt}

%设置目录格式(引文部分）
\usepackage[titles,subfigure]{tocloft}
\newcounter{algoline}
\newcommand\Numberline{\refstepcounter{algoline}\nlset{\thealgoline}}
\AtBeginEnvironment{algorithm}{\setcounter{algoline}{0}}
\makeatletter

\@addtoreset{equation}{section}

\makeatother
\renewcommand{\theequation}{\arabic{section}.\arabic{equation}}

\renewcommand{\cftdot}{$\cdot$}
\renewcommand{\cftdotsep}{1}
\setlength{\cftbeforesecskip}{5pt}
\setlength{\cftbeforesubsecskip}{3pt}
\setlength{\cftbeforesubsubsecskip}{0pt}
\renewcommand{\contentsname}{\zihao{4}\heiti\textmd{目~~录}}
\renewcommand{\cftsecfont}{\songti\zihao{5}}
\renewcommand{\cftsubsecfont}{\songti\zihao{5}}
\renewcommand{\cftsubsubsecfont}{\songti\zihao{5}}
\renewcommand{\cftsecleader}{\cftdotfill{\cftsecdotsep}}
\renewcommand{\cftsecdotsep}{\cftdotsep}
\renewcommand{\cftsecpagefont}{\zihao{5}}
\renewcommand{\cftsubsecpagefont}{\zihao{5}}
\renewcommand{\cftsubsubsecpagefont}{\zihao{5}}
%设置图表编号和章节相关联，参见http://blog.sina.com.cn/s/blog_5e16f1770100h6ts.html
\usepackage[T1]{fontenc}

\numberwithin{figure}{section}
\numberwithin{table}{section}
\setlength{\baselineskip}{18pt}

\newcommand{\yihao}{\fontsize{26pt}{36pt}\selectfont}           % 一号, 1.4 倍行距
\newcommand{\erhao}{\fontsize{22pt}{28pt}\selectfont}          % 二号, 1.25倍行距
\newcommand{\xiaoer}{\fontsize{18pt}{18pt}\selectfont}          % 小二, 单倍行距
\newcommand{\sanhao}{\fontsize{16pt}{24pt}\selectfont}        % 三号, 1.5倍行距
\newcommand{\xiaosan}{\fontsize{15pt}{22pt}\selectfont}        % 小三, 1.5倍行距
\newcommand{\sihao}{\fontsize{14pt}{21pt}\selectfont}            % 四号, 1.5 倍行距
\newcommand{\banxiaosi}{\fontsize{13pt}{19.5pt}\selectfont}    % 半小四, 1.5倍行距
\newcommand{\xiaosi}{\fontsize{12pt}{18pt}\selectfont}            % 小四, 1.5倍行距
\newcommand{\dawuhao}{\fontsize{11pt}{11pt}\selectfont}       % 大五号, 单倍行距
\newcommand{\wuhao}{\fontsize{10.5pt}{15.75pt}\selectfont}    % 五号, 单倍行距
\newcommand{\xiaowu}{\fontsize{9pt}{13.5pt}\selectfont}    %小 五号, 单倍行距

\sloppy
\definecolor{lightgray}{gray}{0.5}

\makeatletter
\newenvironment{breakablealgorithm}
{% \begin{breakablealgorithm}
	\begin{center}
		\refstepcounter{algorithm}% New algorithm
		\hrule height.8pt depth0pt \kern2pt% \@fs@pre for \@fs@ruled
		\renewcommand{\caption}[2][\relax]{% Make a new \caption
			{\raggedright\textbf{算法~\thealgorithm} ##2\par}%
			\ifx\relax##1\relax % #1 is \relax
			\addcontentsline{loa}{algorithm}{\protect\numberline{\thealgorithm}##2}%
			\else % #1 is not \relax
			\addcontentsline{loa}{algorithm}{\protect\numberline{\thealgorithm}##1}%
			\fi
			\kern2pt\hrule\kern2pt
		}
	}{% \end{breakablealgorithm}
		\kern2pt\hrule\relax% \@fs@post for \@fs@ruled
	\end{center}
}
\makeatother

\fancypagestyle{mainstyle}
{
   \fancyhf{}
   \pagenumbering{arabic}
   \fancyhead[L]{\qquad \includegraphics[height=1.14cm]{tongji.pdf}}   %页眉左侧插入同济大学logo
   \fancyhead[R]{\large 毕业设计（论文）~\\}
   \fancyfoot[R]{{\large 共\quad \pageref{LastPage}\quad 页\quad 第\quad \thepage \quad 页}} %偶数页左侧(LE)，奇数页右侧(RO)标页码，oneside打印只用写RO
   \renewcommand{\headrulewidth}{1.5pt}  %页眉横线
   \renewcommand{\footrulewidth}{1.5pt}
}

\fancypagestyle{firststyle}
{
   \fancyhf{}
   \pagenumbering{Roman}
   \fancyhead[L]{\qquad \includegraphics[height=1.14cm]{tongji.pdf}}   %页眉左侧插入同济大学logo
   \fancyhead[R]{\large 毕业设计（论文）~\\}
   \fancyfoot[C]{\large \thepage}
   \renewcommand{\headrulewidth}{1.5pt}  %页眉横线
   \renewcommand{\footrulewidth}{0pt}
}


%以下为修改目录格式的正文内语句，正文内用@命令需用\makeatletter,\makeatother括起来
\makeatletter
\renewcommand{\numberline}[1]{%
	\settowidth\@tempdimb{#1\hspace{0.5em}}%
	\ifdim\@tempdima<\@tempdimb%
	\@tempdima=\@tempdimb%
	\fi%
	\hb@xt@\@tempdima{\@cftbsnum #1\@cftasnum\hfil}\@cftasnumb}
\makeatother


%以下两段修改章节标题格式，参数含义见博客http://blog.sina.com.cn/s/blog_5e16f1770100lqn7.html
\makeatletter
\renewcommand\section{\@startsection {section}{1}{\z@}%
	{-3.5ex \@plus -1ex \@minus -.2ex}%
	{2.3ex \@plus.2ex}%
	{\centering\heiti\zihao{4}}}
\makeatother
\makeatletter
\renewcommand\subsubsection{\@startsection{subsubsection}{2}{2em}%
	{2.3ex \@plus -1ex \@minus -.2ex}%
	{2.3ex \@plus.2ex}%
	{\heiti\zihao{5}}}
\makeatother
\makeatletter
\renewcommand\subsection{\@startsection{subsection}{2}{0em}%
	{2.3ex \@plus -1ex \@minus -.2ex}%
	{2.3ex \@plus.2ex}%
	{\heiti\zihao{5}}}
\makeatother

%下面修改参考文献格式
\makeatletter
\renewenvironment{thebibliography}[1]
{\section*{\refname}%
	\@mkboth{\MakeUppercase\refname}{\MakeUppercase\refname}%
	\list{\@biblabel{\@arabic\c@enumiv}}%
	{\settowidth\labelwidth{\@biblabel{#1}}%
		\leftmargin\labelwidth
		\advance\leftmargin\labelsep
		\advance\leftmargin by 0em%   %设置文本距离左边距距离
		\itemindent 0em%    %设置编号后内容缩进
		\@openbib@code
		\usecounter{enumiv}%
		\let\p@enumiv\@empty
		\renewcommand\theenumiv{\@arabic\c@enumiv}}%
	\sloppy
	\clubpenalty4000
	\@clubpenalty \clubpenalty
	\widowpenalty4000%
	\sfcode`\.\@m}
{\def\@noitemerr
	{\@latex@warning{Empty `thebibliography' environment}}%
	\endlist}
\makeatother

\makeatletter
\AtBeginDocument{\let\c@listing\c@figure}
\makeatother
